package com.flying.ouyu.net.handler;

import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;

import com.flying.client.network.IMsgHandler;
import com.flying.client.network.NetworkProvider;
import com.flying.client.network.msg.ORMsg;
import com.flying.client.network.msg.OWMsg;
import com.flying.client.utils.Logger;
import com.flying.ouyu.net.MessageType;
import com.flying.ouyu.net.NetworkProxy;

public class LoginHandler implements IMsgHandler{
	private static final Logger logger = Logger.getLogger(LoginHandler.class.getName());
	
	private static Object instanceLocker = new Object();
	private static LoginHandler _instance = null;
	
	public static LoginHandler getInstance()
	{
		if (_instance != null)
			return _instance;
		
		synchronized (instanceLocker) {
			if (_instance == null)
			{
				_instance = new LoginHandler();
			}
		}
		
		return _instance;
	}
	
	private LoginHandler(){}
	
	public void onMsg(ORMsg rMsg) {
		logger.debug("onMsg rMsg="+rMsg);
	}
	
	public void login(String userName,String password)
	{
		OWMsg msg = createLoginWMsg(userName,password);
		NetworkProxy.getInstance().send(msg);
	}
	
	private OWMsg createLoginWMsg(String userName,String password)
	{
		OWMsg msg = new OWMsg(MessageType.Login);
		ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
		
		return msg;
	}
}
